package com.zit.presentation.interceptor;

import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class TrimInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ac = invocation.getInvocationContext();
		Map<String, Object> map = ac.getParameters();
		Set<Entry<String, Object>> set = map.entrySet();
		for (Entry<String, Object> e : set) {
			String[] value = (String[])e.getValue();
			for (int i = 0; i < value.length; i++) {
				String s = value[i];
				if(s!=null){
					s = s.trim() ;
					if(s.equals("")){
						s = null ;
					}
				}
				value[i] = s ;
			}
		}
		return invocation.invoke();
	}

}
